package com.java1412.com.java1412.controller;

import com.java1412.entity.User;
import com.java1412.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author java1412
 * @version 1.0.0
 * @create 2021-10-14 16:35
 * @qq 1017080724
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * @Description: 保存用户
     */
    @PostMapping("save-user")
    public Object saveUser() {
        return userService.saveOne(new User("小小", "女", 3));
    }

    /**
     * @Description: 批量保存用户
     */
    @RequestMapping("save-user2")
    public Object saveUser2() {
        List<User> userList = new ArrayList<>();
        userList.add(new User(1L, "小小", "女", 3, new Date(), new Date(), 1));
        userList.add(new User(2L, "哈哈", "女", 2, new Date(), new Date(), 0));
        userList.add(new User(3L, "嘿嘿", "女", 3, new Date(), new Date(), 1));
        userList.add(new User(4L, "喜喜", "女", 4, new Date(), new Date(), 0));
        userList.add(new User(5L, "呵呵", "女", 5, new Date(), new Date(), 1));
        return userService.insertForeach(userList);
    }

    /**
     * @Description: 获取用户列表
     */
    @GetMapping("list-user")
    public Object listUser() {
        return userService.list();
    }

}
